package com.wfm.leetcode.editor.cn;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 最大数
 * 2025-02-26 22:38:15
 * 时间复杂度：O(nlogn)
 * 空间复杂度：O(n)
 */
class LargestNumber {

//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String largestNumber(int[] nums) {
        // 将整数数组转换成字符串
        String[] strs = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            strs[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(strs, (o1, o2) -> (o2+o1).compareTo(o1+o2));
        StringBuilder sb = new StringBuilder();
        for (String str : strs) {
            sb.append(str);
        }
        return sb.charAt(0) == '0' ? "0" : sb.toString();
    }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) {
        Solution solution = new LargestNumber().new Solution();
        int[] nums = {3,30,34,5,9};
        String largestNumber = solution.largestNumber(nums);
        System.out.println(largestNumber);
        
    }
}